//
//  HRsetupTableViewController.m
//  haierapp
//
//  Created by gaotangzhang on 14-8-19.
//  Copyright (c) 2014年 haier. All rights reserved.
//

#import "HRsetupTableViewController.h"

@interface HRsetupTableViewController ()

@property (weak, nonatomic) IBOutlet UILabel *versionLabel;
@property (weak, nonatomic) IBOutlet UIButton *logoutButton;
@property (weak, nonatomic) IBOutlet UIButton *clearCacheButton;

@end

@implementation HRsetupTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    //清除多余的分割线
    UIView *footerView=[[UIView alloc]init];
    footerView.backgroundColor=[UIColor clearColor];
    [self.tableView setTableFooterView:footerView];
    
    //按钮背景图片
    UIImage *redImage=[[UIImage imageNamed:@"red_btn3"]resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
    
    UIImage *whiteImage=[[UIImage imageNamed:@"cancel_btn"]resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
    
    [_logoutButton setBackgroundImage:redImage forState:UIControlStateNormal];
    [_logoutButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_clearCacheButton setBackgroundImage:whiteImage forState:UIControlStateNormal];
    [_clearCacheButton setTitleColor:[UIColor colorFromHexRGB:@"606060"] forState:UIControlStateNormal];
    
    
    self.title=@"设置";
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Methods
- (IBAction)onTapLogoutAction:(id)sender {
    [[HRCommonData shareCommonData] logout];
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)onTapClearCache:(id)sender {
    
    [[HRCommonData shareCommonData] clearProductsFromShopCar];//清除本地购物车数据
    [HRCommonData shareCommonData].hasNewOrder=YES;
    [HRCommonData shareCommonData].hasNewShopCar=YES;
    
    [self showSuccessHud:@"缓存已清除"];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(HUD_DELAY_HIDE_SECOND * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.navigationController popViewControllerAnimated:YES];
    });
    
}

#pragma mark - TableView Delegate
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section==0) {
        UIView *footerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
        [footerView setBackgroundColor:[UIColor colorFromHexRGB:@"ECECEC"]];
        
        return footerView;
    }
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section==0) {
        return 10.0f;
    }
    return 0.0f;
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    if (indexPath.section==1 && indexPath.row==0) {
        NSString *telUrl=@"telprompt:4006999999";
        NSURL *url=[NSURL URLWithString:telUrl];
        
        [[UIApplication sharedApplication] openURL:url];
    }
}


@end
